import requests
import json
import faker
import config  # 我在work_wechat这个文件夹下面新建的文件

fk = faker.Faker()




url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={config.cropid}&corpsecret={config.secretid}'

req = requests.get(url)
accesstoken=req.json()['access_token']

url = f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+accesstoken+"&random=69152"

print  ('url===='+url)
# python的json可以编码解码
# json.loads()：json格式的字符串------------>字典
# json.dumps()：字典转---------------------->json格式的字符串
payload = json.dumps({
    "touser": config.touser,
    "toparty": config.toparty,
    "totag": config.totag,
    "msgtype": "text",
    "agentid": config.agentid_ceshi1,
    "text": {
        "content": "白眉大叔 测试 已备份成功2，请查收！"
    },
    "safe": 0,
    "enable_id_trans": 0,
    "enable_duplicate_check": 0
})
headers = {
    'User-Agent': fk.user_agent(),
    'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
